<template>
	<section>
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
			<el-form :inline="true" :model="filters">
<!--				<el-form-item>
					<div class="block">
						<el-date-picker :clearable="true"
								v-model="filters.value"
								type="date"
								placeholder="选择日期"
								value-format='yyyyMMdd'>
						</el-date-picker>
					</div>
				&lt;!&ndash;	<el-input v-model="filters.value"  placeholder="答辩日期："></el-input>&ndash;&gt;
				</el-form-item>
				<el-form-item  >
					<el-select v-model="filters.subjectid" placeholder="请选择学科"  style="width: 210px;" :clearable="true">
						<el-option
								v-for="item in subjectOptions"
								:key="item.id"
								:label="item.subjectname"
								:value="item.id">
						</el-option>
					</el-select>
					&lt;!&ndash;<el-input v-model="filters.value"  placeholder="学科："></el-input>&ndash;&gt;
				</el-form-item>
				<el-form-item>
					<el-select v-model="filters.classnum" placeholder="请选择班级" style="width: 210px;" :clearable="true">
						<el-option
								v-for="item in classOptions"
								:key="item.classnum"
								:label="item.classnum"
								:value="item.classnum">
						</el-option>
					</el-select>
					&lt;!&ndash;<el-input v-model="filters.classnum"  placeholder="班级："></el-input>&ndash;&gt;
				</el-form-item>-->
				<el-form-item>
					<el-input v-model="filters.name"  placeholder="学生姓名：" :clearable="true"></el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" v-on:click="getClasses">查询</el-button>
				</el-form-item>
			</el-form>
		</el-col>

		<!--列表-->
		<el-table :data="classes" highlight-current-row v-loading="listLoading" @selection-change="selsChange" style="width: 100%;">
			<el-table-column type="index" width="60"/>
            <el-table-column prop="id" label="id" width="120"  sortable v-if="false"/>
            <el-table-column prop="id" label="答辩id"   v-if="false"/>
            <el-table-column prop="examno" label="答辩日期"   />
            <el-table-column prop="classid" label="班级id"   v-if="false"/>
            <el-table-column prop="classnum" label="班级编号"   />
            <el-table-column prop="studentid" label="学生id"  v-if="false" />
            <el-table-column prop="studentname" label="学生姓名"   />
			<el-table-column prop="studentphone" label="学生电话"   />
            <el-table-column prop="teacherid" label="评分人id"  v-if="false" />
            <el-table-column prop="teachername" label="评分人"   v-if="false"/>
            <el-table-column prop="level" label="等级"   />
			<el-table-column label="问题"  :show-overflow-tooltip="true" >
				<template slot-scope="scope">
					<span v-html="scope.row.question"></span>
				</template>
			</el-table-column>
			<el-table-column  label="建议"  :show-overflow-tooltip="true" >
				<template slot-scope="scope">
					<span v-html="scope.row.suggestion"></span>
				</template>
			</el-table-column>
			<el-table-column label="操作" width="150">
				<template scope="scope">
					<el-button size="small" @click="handleEdit(scope.$index, scope.row)" :disabled="scope.row.state===1">评分</el-button>
				</template>
			</el-table-column>
		</el-table>
		<!--工具条-->
		<el-col :span="24" class="toolbar">
			<el-pagination layout="prev, pager, next" @current-change="handleCurrentChange" :page-size="pageSize" :total="total" style="float:right;">
			</el-pagination>
		</el-col>
		<!--编辑界面-->
		<!--<el-dialog title="编辑" :visible.sync="editFormVisible" :close-on-click-modal="false">
			<el-form :model="editForm" label-width="80px" :rules="editFormRules" ref="editForm">
			&lt;!&ndash;	<el-form-item label="答辩id" prop="id" >
					<el-input v-model="editForm.id" auto-complete="off" :disabled="true"></el-input>
				</el-form-item>&ndash;&gt;
				<el-form-item label="答辩日期" prop="examno">
					<el-input v-model="editForm.examno" auto-complete="off" :disabled="true"></el-input>
				</el-form-item>
				<el-form-item label="班级编号" prop="classnum">
					<el-input v-model="editForm.classnum" auto-complete="off" :disabled="true"></el-input>
				</el-form-item>
				<el-form-item label="学生姓名" prop="studentname">
					<el-input v-model="editForm.studentname" auto-complete="off" :disabled="true"></el-input>
				</el-form-item>
				<el-form-item label="答辩等级" prop="studentname">
					<el-select v-model="editForm.level" size="70px" placeholder="请选择" >
						<el-option
								v-for="item in options"
								:key="item.levelvalue"
								:label="item.levelvalue"
								:value="item.levelvalue">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="问题" prop="question">
					<el-input v-model="editForm.question" auto-complete="off"></el-input>
				</el-form-item>
				<el-form-item label="答辩建议" prop="suggestion">
					<el-input v-model="editForm.suggestion" auto-complete="off"></el-input>
				</el-form-item>



			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click.native="editFormVisible = false">取消</el-button>
				<el-button type="primary" @click.native="editSubmit" :loading="editLoading">提交</el-button>
			</div>
		</el-dialog>-->
		<el-dialog title="编辑" :visible.sync="editFormVisible" :close-on-click-modal="false">
			<el-form :model="editForm" label-width="120px" :rules="editFormRules" ref="editForm" >
				<el-row>
					<el-col :span="12">
						<el-form-item label="答辩日期：" prop="examno">
							<el-input v-model="editForm.examno" auto-complete="off" :disabled="true"  size="small" style="width: 180px;height: 35px;"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="班级编号：" prop="classnum">
							<el-input v-model="editForm.classnum" auto-complete="off" :disabled="true" size="small" style="width: 180px;height: 35px;"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="12">
						<el-form-item label="学生姓名：" prop="studentname">
							<el-input v-model="editForm.studentname" auto-complete="off" :disabled="true" size="small" style="width: 180px;height: 35px;"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="答辩总成绩：" prop="totalscore" >
							<el-input v-model="editForm.totalscore" auto-complete="off" size="small" style="width: 180px;height: 35px;"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="12">
						<el-form-item label="自我介绍成绩：" prop="selfintroscore" >
							<el-input-number v-model="editForm.selfintroscore" :max="10" :min="0" style="width: 180px;height: 35px;" @change="sumTotalScore"></el-input-number>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="项目介绍成绩：" prop="projectintroscore" >
							<el-input-number v-model="editForm.projectintroscore" :max="10" :min="0" style="width: 180px;height: 35px;" @change="sumTotalScore"></el-input-number>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="12">
						<el-form-item label="技术表达成绩：" prop="techologyscore">
							<el-input-number v-model="editForm.techologyscore" :max="10" :min="0" style="width: 180px;height: 35px;" @change="sumTotalScore"></el-input-number>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="业务表达成绩：" prop="businessscore">
							<el-input-number v-model="editForm.businessscore" :max="10" :min="0" style="width: 180px;height: 35px;" @change="sumTotalScore"></el-input-number>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="12">
						<el-form-item label="自信表现成绩：" prop="confidencescore">
							<el-input-number v-model="editForm.confidencescore" :max="10" :min="0" style="width: 180px;height: 35px;" @change="sumTotalScore"></el-input-number>
						</el-form-item>
					</el-col>
				</el-row>
				<el-form-item label="问题:" prop="question">
					<!--<el-input v-model="editForm.question" auto-complete="off"></el-input>-->
					<quill-editor  v-model="editForm.question"  :options="editorOption"   >
						<!-- 自定义toolar -->
						<div id="toolbar" slot="toolbar">
							<!-- Add a bold button -->
							<button class="ql-bold" title="加粗">Bold</button>
							<button class="ql-italic" title="斜体">Italic</button>
							<button class="ql-underline" title="下划线">underline</button>
							<button class="ql-strike" title="删除线">strike</button>
							<button class="ql-blockquote" title="引用"></button>
							<button class="ql-code-block" title="代码"></button>
							<button class="ql-header" value="1" title="标题1"></button>
							<button class="ql-header" value="2" title="标题2"></button>
							<!--Add list -->
							<button class="ql-list" value="ordered" title="有序列表"></button>
							<button class="ql-list" value="bullet" title="无序列表"></button>
							<!-- Add font size dropdown -->
							<select class="ql-header" title="段落格式">
								<option selected>段落</option>
								<option value="1">标题1</option>
								<option value="2">标题2</option>
								<option value="3">标题3</option>
								<option value="4">标题4</option>
								<option value="5">标题5</option>
								<option value="6">标题6</option>
							</select>
							<select class="ql-size" title="字体大小">
								<option value="10px">10px</option>
								<option value="12px">12px</option>
								<option value="14px">14px</option>
								<option value="16px" selected>16px</option>
								<option value="18px">18px</option>
								<option value="20px">20px</option>
							</select>
							<select class="ql-font" title="字体">
								<option value="SimSun">宋体</option>
								<option value="SimHei">黑体</option>
								<option value="Microsoft-YaHei">微软雅黑</option>
								<option value="KaiTi">楷体</option>
								<option value="FangSong">仿宋</option>
								<option value="Arial">Arial</option>
							</select>
							<!-- Add subscript and superscript buttons -->
							<select class="ql-color" value="color" title="字体颜色"></select>
							<select class="ql-background" value="background" title="背景颜色"></select>
							<select class="ql-align" value="align" title="对齐"></select>
							<button class="ql-clean" title="还原"></button>
							<!-- You can also add your own -->
						</div>
					</quill-editor>
				</el-form-item>
				<el-form-item label="答辩建议:" prop="suggestion">
					<!--<el-input v-model="editForm.suggestion" auto-complete="off"></el-input>-->
					<quill-editor  v-model="editForm.suggestion"  :options="editorOptionSuggerstion"   >
						<!-- 自定义toolar -->
						<div id="toolbar1" slot="toolbar">
							<!-- Add a bold button -->
							<button class="ql-bold" title="加粗">Bold</button>
							<button class="ql-italic" title="斜体">Italic</button>
							<button class="ql-underline" title="下划线">underline</button>
							<button class="ql-strike" title="删除线">strike</button>
							<button class="ql-blockquote" title="引用"></button>
							<button class="ql-code-block" title="代码"></button>
							<button class="ql-header" value="1" title="标题1"></button>
							<button class="ql-header" value="2" title="标题2"></button>
							<!--Add list -->
							<button class="ql-list" value="ordered" title="有序列表"></button>
							<button class="ql-list" value="bullet" title="无序列表"></button>
							<!-- Add font size dropdown -->
							<select class="ql-header" title="段落格式">
								<option selected>段落</option>
								<option value="1">标题1</option>
								<option value="2">标题2</option>
								<option value="3">标题3</option>
								<option value="4">标题4</option>
								<option value="5">标题5</option>
								<option value="6">标题6</option>
							</select>
							<select class="ql-size" title="字体大小">
								<option value="10px">10px</option>
								<option value="12px">12px</option>
								<option value="14px">14px</option>
								<option value="16px" selected>16px</option>
								<option value="18px">18px</option>
								<option value="20px">20px</option>
							</select>
							<select class="ql-font" title="字体">
								<option value="SimSun">宋体</option>
								<option value="SimHei">黑体</option>
								<option value="Microsoft-YaHei">微软雅黑</option>
								<option value="KaiTi">楷体</option>
								<option value="FangSong">仿宋</option>
								<option value="Arial">Arial</option>
							</select>
							<!-- Add subscript and superscript buttons -->
							<select class="ql-color" value="color" title="字体颜色"></select>
							<select class="ql-background" value="background" title="背景颜色"></select>
							<select class="ql-align" value="align" title="对齐"></select>
							<button class="ql-clean" title="还原"></button>
							<!-- You can also add your own -->
						</div>
					</quill-editor>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click.native="editFormVisible = false">取消</el-button>
				<el-button type="primary" @click.native="editSubmit" :loading="editLoading">提交</el-button>
			</div>
		</el-dialog>

	</section>
</template>

<script>
	import util from '../../common/js/util'
	import { getUserListPage, removeUser, batchRemoveUser, editUser, addUser } from '../../api/api';
    import ElRow from "element-ui/packages/row/src/row";

    // import { quillEditor } from "vue-quill-editor"; //调用编辑器
    // import 'quill/dist/quill.core.css';
    // import 'quill/dist/quill.snow.css';
    // import 'quill/dist/quill.bubble.css';
    //import quillConfig from '../../common/js/quill-config';

    import {
        Quill,
        quillEditor
    } from 'vue-quill-editor'
    import 'quill/dist/quill.core.css'
    import 'quill/dist/quill.snow.css'
    import 'quill/dist/quill.bubble.css'
    //引入font.css
    import '../../css/font.css'

    // 自定义字体大小
    let Size = Quill.import('attributors/style/size')
    Size.whitelist = ['10px', '12px', '14px', '16px', '18px', '20px']
    Quill.register(Size, true)

    // 自定义字体类型
    var fonts = ['SimSun', 'SimHei', 'Microsoft-YaHei', 'KaiTi', 'FangSong', 'Arial', 'Times-New-Roman', 'sans-serif',
        '宋体', '黑体'
    ]
    var Font = Quill.import('formats/font')
    Font.whitelist = fonts
    Quill.register(Font, true)


    export default {
        components: {ElRow,quillEditor},
        data() {
            return {
                editorOption: {
                    placeholder: "请输入",
                    theme: "snow", // or 'bubble'
                    modules: {
                        toolbar: {
                            container: '#toolbar'
                        }
                    }
                },
                editorOptionSuggerstion:{
                    placeholder: "请输入",
                    theme: "snow", // or 'bubble'
                    modules: {
                        toolbar: {
                            container: '#toolbar1'
                        }
                    }
				},
                options: [{
                    levelvalue: '优',
                    label: '优'
                }, {
                    levelvalue: '良',
                    label: '良'
                }, {
                    levelvalue: '中',
                    label: '中'
                }, {
                    levelvalue: '差',
                    label: '差'
                }],
				//学科列表
                subjectOptions:[],
				//班级列表
                classOptions:[],
                levelvalue: '',
                filters: {
                    value: '',
                    name: '',
					classnum:'',
                    subjectid:''
                },
                state:0,
                classes: [],
                total: 0,
                currentPage: 1,
                pageSize: 10,
                listLoading: false,
                sels: [],//列表选中列
                selectList: [],//选中答辩班级的list,
				selectNo:'',
                editFormVisible: false,//编辑界面是否显示
                editLoading: false,
                editFormRules: {
                    level: [
                        {required: true, message: '请选择答辩等级', trigger: 'blur'}
                    ]

                },
                //编辑界面数据
                editForm: {
                    id:'',
                    examno: '',
                    classnum: '',
                    studentname: '',
                    level:'',
                    question:'',
                    suggestion:'',
					score:5,
                    projectintroscore:0,
                    selfintroscore:0,
                    techologyscore:0,
                    businessscore:0,
                    confidencescore:0,
                    totalscore:0,
                },



            }
        },
        methods: {

            handleCurrentChange(val) {
                this.currentPage = val;
                this.getClasses();
            },
            //获取用户列表
            getClasses() {
                let para = {
                    currentPage: this.currentPage,
                    pageSize: 10,
                    value: this.filters.value,
                    name: this.filters.name,
                    subjectid:this.filters.subjectid,
                    classnum: this.filters.classnum,
                    examid:this.$route.query.id
                };
                this.listLoading = true;

                this.$http.post("/examResult/list", para).then((res) => {
                   // if(res.data.list){
                        this.classes = res.data.list;
                  //  }
					//if( res.data.total){
                        this.total = res.data.total;
                   // }
                    this.listLoading = false;
                });
            },

            //显示编辑界面
            handleEdit: function (index, row) {
                this.editFormVisible = true;
                this.editForm = Object.assign({}, row);
            },

            //编辑
            editSubmit: function () {
                this.$refs.editForm.validate((valid) => {
                    if (valid) {
                        this.$confirm('确认提交吗？', '提示', {}).then(() => {
                            this.editLoading = true;
                            //NProgress.start();
                            let para = Object.assign({}, this.editForm);
                            this.$http.put("/examResult/exam", para).then((res) => {
                                this.editLoading = false;
                                //NProgress.done();
                                this.$message({
                                    message: '提交成功',
                                    type: 'success'
                                });
                                this.$refs['editForm'].resetFields();
                                this.editFormVisible = false;
                                this.getClasses();
                            });
                        });
                    }
                });
            },

            selsChange: function (sels) {
                this.sels = sels;
            },

			//获取所有学科
			selectSubjects:function () {
				this.$http.post("/subject/list").then((res)=>{
					if(res.data){
					    this.subjectOptions=res.data;
					}
				})
            },
			//获取所有班级
			selectClasses:function () {
				this.$http.post("/class/classList").then((res)=>{
					if(res.data){
						this.classOptions=res.data;
					}
				})
			},
            sumTotalScore:function () {
				this.editForm.totalscore=this.editForm.selfintroscore+ this.editForm.selfintroscore+this.editForm.techologyscore+this.editForm.businessscore+this.editForm.confidencescore
            }
        },
        mounted() {
             this.getClasses();
             this.selectSubjects();
             this.selectClasses();
        }
    }

</script>

<style scoped>

</style>
<style>
/*.el-input.is-disabled .el-input__inner {
		background-color: #F5F7FA;
		border-color: #E4E7ED;
		color: #C0C4CC;
		cursor: not-allowed;
		height: 35px;
		width: 180px;
	}
	.el-input--small .el-input__inner {
		height: 35px;
		line-height: 32px;
		width: 180px;
	}
	.el-dialog {
		position: relative;
		margin: 0 auto 50px;
		border-radius: 2px;
		-webkit-box-shadow: 0 1px 3px rgba(0,0,0,.3);
		box-shadow: 0 1px 3px rgba(0,0,0,.3);
		box-sizing: border-box;
		width: 65%;
	}
	.el-input-number {
		position: relative;
		display: inline-block;
		line-height: 35px;
		height: 35px;
		width: 180px;
	}
	.el-input__inner{
		height: 35px;
		width: 180px;
	}
	.el-input {
		position: relative;
		display: inline-block;
		line-height: 35px;
		height: 35px;
		width: 180px;
	}*/
</style>